<template>
	<view class="">
		{{time}}
	</view>
</template>

<script>
	export default {
		props:{
			index:{
				default:0,
				type:Number
			},
			times:{
				default:'',
				type:String
			}
		},
		data(){
			return {
				time:'0小时0分',
				timeName:null
			}
		},
		created() {
			this.getTime();
			if(this.timeName==null){
				this.timeName = setInterval(()=>{
					this.getTime();
				},60000)
			}
		},
		beforeUnmount(){
			clearInterval(this.timeName);
		},
		methods:{
			getTime(){
				var nowTime = new Date();
				var oldTime = new Date(this.times);
				var times = oldTime.getTime()-nowTime.getTime();
				// 剩余天数
				var d = Math.floor(times/(24*3600*1000));
				// 剩余小时
				var h = Math.floor((times%(24*3600*1000))/(3600*1000));
				// 剩余分钟
				var m = Math.floor(((times%(24*3600*1000))%(3600*1000))/(60*1000));
				// 剩余秒数
				var s = Math.round(((times%(24*3600*1000))%(3600*1000))%(60*1000)/1000);
				this.time = h+'小时'+m+'分钟'
				if(h<=0&&m<=0){
					clearInterval(this.timeName);
					this.$emit('delOrder',this.index);
				}
			},
			delOrder(){
				
			},
			
		}
	}
</script>

<style>
</style>